package com.hrm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hrm.dto.EmpWelfareDTO;
import com.hrm.entity.MyPage;
import com.hrm.service.EmpWelfareService;
import com.hrm.utils.JsonMsg;
import com.hrm.utils.Layui;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: 朱晓龙
 * @Date: 2020/6/1 21:10
 * @Description: 员工福利管理控制器
 */
@Controller
@RequestMapping("/welfare")
public class EmpWelfareController {

    @Autowired
    private EmpWelfareService welfareService;

    /**
     * 进入福利管理界面
     *
     * @return String
     */
    @RequestMapping("/welfarePage.html")
    public String welfareList() {

        return "welfareManagement/welfarePage";
    }

    @RequestMapping("/empWelfareList.html")
    @ResponseBody
    public ResponseEntity<Layui> welfareList(MyPage myPage) {
        PageHelper.startPage(myPage.getPageNum(), myPage.getPageSize());
        List<EmpWelfareDTO> empWelfareDTOList = welfareService.empWelfareList();
        PageInfo pageInfo = new PageInfo(empWelfareDTOList, 5);
        Layui layui = Layui.data(pageInfo.getTotal(), pageInfo.getList());

        return ResponseEntity.ok(layui);
    }

    /**
     * 跳转到福利详情页面
     *
     * @return String
     */
    @RequestMapping("/welfareInfo.html")
    public String welfareInfo() {
        return "welfareManagement/welfareInfo";
    }

    @RequestMapping("/updateWelfareInfo.html")
    @ResponseBody
    public JsonMsg updateWelfareInfo(EmpWelfareDTO empWelfareDTO){
        boolean isSuccess = welfareService.updateWelfareInfo(empWelfareDTO);
        return isSuccess ? JsonMsg.success() : JsonMsg.fail();
    }

}
